#pragma once

#include <opencv/cv.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

#include <iostream>
using namespace cv;

#include "CommonDefs.h"

class COpenCVImg
{
public:
	COpenCVImg(void);
	virtual ~COpenCVImg(void);
	void loadImg(char* strFileName,bool bColor);
	void CreateImg(CvSize imgSize, int iDepth, int iChannel);
	int saveImg(char* strFileName);
	void GetPixelFromColorImg(int xIdx, int yIdx, uchar& red, uchar& green, uchar& blue);
	void GetPixelFromGrayImg(int xIdx, int yIdx, uchar& gray);	
	void FillImageRegionWithSingleColor(Rect& r, uchar red, uchar green, uchar blue);
	void FillImageRegionWithSingleGray(Rect& r, uchar gray);
	//copy the content from iplimage to mat
	void CopyImageRegionToSingleChannelMat(IplImage* mat, Rect& r);
	//create scaled version image
	void CreateScaledImg(COpenCVImg* srcImg, float fScaleFactor);
	//
	IplImage* GetImgPointer() {return m_pImg;}
	inline int GetWidth() 
	{ 
		if(m_pImg!=NULL) 
			return m_pImg->width;
		else
			return -1;
	}
	inline int GetHeight() 
	{ 
		if(m_pImg!=NULL) 
			return m_pImg->height;
		else
			return -1;
	}
	inline int GetDepth()
	{
		if(m_pImg!=NULL) 
			return m_pImg->depth;
		else
			return -1;
	}
	inline int GetChannels()
	{
		if(m_pImg!=NULL) 
			return m_pImg->nChannels;
		else
			return -1;
	}
	inline bool isColor()
	{
		return m_bColor;
	}
protected:
	IplImage* m_pImg;
	bool m_bColor;
};

